// $Id: swap_compare.cpp 2 2009-09-02 08:47:42Z joseph2002 $
/*
 * Copyright 2009 Joseph Wu
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
 *
 * For more information, see http://xpcomplus.sourceforge.net
 */

#include <boost/test/unit_test.hpp>
#include <xpcom/result.hpp>
#include <xpcom/result_code.hpp>

BOOST_AUTO_TEST_CASE(test_swap_compare)
{
    using namespace xpcom;

    result r1 = NS_ERROR_FILE_IS_LOCKED;
    result r2 = NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA;
    result r3 = r1;

    BOOST_CHECK(r1 == NS_ERROR_FILE_IS_LOCKED);
    BOOST_CHECK(NS_ERROR_FILE_IS_LOCKED == r1);
    BOOST_CHECK(r1 == r3);
    BOOST_CHECK(!(r1 == r2));
    BOOST_CHECK(r1 != r2);
    BOOST_CHECK(r1 != NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA);
    BOOST_CHECK(!(r1 == NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA));
    BOOST_CHECK(NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA != r1);

    r1.swap(r2);
    BOOST_CHECK(r1 == NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA);
    BOOST_CHECK(r2 == NS_ERROR_FILE_IS_LOCKED);

    swap(r1, r2);
    BOOST_CHECK(r1 == NS_ERROR_FILE_IS_LOCKED);
    BOOST_CHECK(r2 == NS_SUCCESS_LOSS_OF_INSIGNIFICANT_DATA);

    BOOST_CHECK(r1 > r2);
    BOOST_CHECK(r1 > NS_OK);
    BOOST_CHECK(r2 < r3);
}
